package com.zhuchaooasystem.adapter.holder;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zhuchaooasystem.R;
import com.zhuchaooasystem.widget.SingleChoiceDialog;


/**
 * @author yinsi
 */
public class SingleChoiceHolder extends BaseViewHolder<String> {
    //----
    private LinearLayout linear_rootview;
    private TextView txt_name;
    private ImageView iv_check;
    //----
    private SingleChoiceDialog dialog;

    public SingleChoiceHolder(ViewGroup parent, SingleChoiceDialog dialog) {
        super(parent, R.layout.item_single_choice);
        this.dialog = dialog;
        //----
        linear_rootview = $(R.id.item_single_choice_linear_rootview);
        iv_check = $(R.id.item_single_choice_iv_check);
        txt_name = $(R.id.item_single_choice_txt_name);
    }

    @Override
    public void setData(final String name) {
        txt_name.setText(name);
        //----选中状态
        if (dialog.getCur_position() == getDataPosition()) {
            iv_check.setBackgroundResource(R.drawable.ic_oval_checked);
        } else {
            iv_check.setBackgroundResource(R.drawable.ic_oval_uncheck);
        }
        linear_rootview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.setCur_position(getDataPosition());
            }
        });
    }

}
